import MyTable from '@/components/MyTable';
import {
  findByAgentBySelectList,
  findByPageBackAgentReChangeList,
} from '@/services/agent';
import { editAgentUpdate } from '@/services/users';
import { ProFormSelect } from '@ant-design/pro-components';
import React from 'react';

import FormModalBtn from '@/components/FormModalBtn';

const AgentReChangeSetting: React.FC<any> = (props) => {
  const { user } = props;
  const colmuns = [
    {
      title: '用户姓名',
      key: 'name',
      dataIndex: 'name',
      search: false,
    },
    {
      title: '原等级',
      key: 'oldAgentName',
      dataIndex: 'oldAgentName',
      search: false,
    },
    {
      title: '原管理上级',
      key: 'oldParentUserName',
      dataIndex: 'oldParentUserName',
      search: false,
    },
    {
      title: '新等级',
      key: 'agentName',
      dataIndex: 'agentName',
      search: false,
    },
    {
      title: '新管理上级',
      key: 'parentUserName',
      dataIndex: 'parentUserName',
      search: false,
    },
    {
      title: '备注说明',
      key: 'remark',
      dataIndex: 'remark',
      search: false,
    },
    {
      title: '申请时间',
      key: 'create_date',
      dataIndex: 'create_date',
      valueType: 'dateTime',
    },
    {
      title: '操作员',
      key: 'operatorName',
      dataIndex: 'operatorName',
      search: false,
    },
  ];
  // @ts-ignore
  // @ts-ignore
  let toolbar = [
    <FormModalBtn
      initialValues={{
        name: user?.name,
        id: user?.id,
        agentName: user?.agentName,
        parentName: user?.parentName,
      }}
      title="代理升级"
      btnText="代理升级"
      columns={[
        {
          title: 'userId',
          dataIndex: 'id',
          key: 'id',
          width: 'md',
          readonly: true,
          formItemProps: {
            hidden: true,
          },
        },
        {
          title: '姓名',
          dataIndex: 'name',
          key: 'name',
          width: 'md',
          readonly: true,
        },
        {
          title: '当前等级',
          dataIndex: 'agentName',
          key: 'agentName',
          width: 'md',
          readonly: true,
        },
        {
          title: '当前管理上级',
          dataIndex: 'parentName',
          key: 'parentName',
          readonly: true,
          width: 'md',
        },
        {
          title: '升级等级',
          dataIndex: 'agentId',
          key: 'agentId',
          width: 'sm',
          renderFormItem: () => (
            <ProFormSelect
              debounceTime={300}
              request={async () => {
                return await findByAgentBySelectList();
              }}
            />
          ),
        },
      ]}
      request={editAgentUpdate}
    />,
  ];
  // @ts-ignore
  return (
    <MyTable
      toolbar={() => toolbar}
      params={{ userId: user.id }}
      request={findByPageBackAgentReChangeList}
      columns={colmuns}
    />
  );
};

export default AgentReChangeSetting;
//96, 100, 104, 105, 107.239, 230, 361, 1161, 1162, 1148, 238
